ResComp 1.3 (november 2014)
Stephane Dallongeville
https://code.google.com/p/sgdk/

ResComp is part of SGDK (aka Sega Genesis Dev Kit).
It allows to compile different type of resource and output them in assembly source form.

Usage: rescomp resource.rc [out.s] [-noheader]

If output file is not specified it takes the same name as input with .s extension.
Note that the header file (.h) is generated except if you use the -noheader parameter.

Supported resource type:
- BITMAP    bitmapped image type resource, used for the Bitmap SGDK engine (do not use it as tile resource).
- PALETTE   palette type resource, used as color input for Bitmap, Image or Sprite resource.
- TILESET   tileset type resource, contains tiles data which are used by Image or Sprite resource.
- MAP       map type resource (tilemap data).
- IMAGE     image type resource, internally contains Palette, Tileset and Map data and can be used to draw a complete background.
- SPRITE    sprite type resource, used to handle sprites with the SGDK Sprite engine.
- TFM       TFM music type resource (.tfd or .tfc file), used to play music.
- XGM       XGM music type resource (.vgm or .xgm file), used to play music.
- VGM       VGM music type resource (.vgm file), used to play music.
- WAV       WAV sound type resource (.wav file), used to play sample sound data.
- PCM       PCM sound type resource (.pcm file), used to play sample sound data.
- BIN       any binary data file which do not need any specific conversion or processing.


PALETTE
-------
Take a .pal file or an image as input and transform it in SGDK Palette structure.
If the input image is 1 pixel heigth then the width is the palette size and pixel X represent color data at index X.
In others cases the usual image palette data is used instead.

Palette is used as color input for Bitmap, Image and Sprite resources.

Syntax:
PALETTE name file [index]

    name        name of the output Bitmap structure
    file        path of the input image file (should be 8bpp .bmp or .png) or .pal file
    index       start index where to copy the palette in Sega Genesis CRAM.


BITMAP
------
Take an image as input and transform it in SGDK Bitmap structure.
Bitmap image structure is used for the SGDK BMP (bitmap) engine, do not use it for tiled image.

Syntax:
BITMAP name img_file [compression]

    name          name of the output Bitmap structure
    img_file      path of the input image file (should be 8bpp .bmp or .png)
    compression   compression type (use unpackBitmap(..) to unpack)
                    -1 = AUTO (use best compression scheme)
                    0 = NONE (no compression)
                    1 = APLIB (aplib library)
                    2 = LZKN (Konami LZW compression, disable for legal reason)
                    3 = RLE (4bits RLE compression)
                    4 = RLE MAP (tilemap adapted RLE)


TILESET
-------
Take an image as input and transform it in SGDK TileSet structure.
TileSet is used as tiles source for Image and Sprite.

Syntax:
TILESET name img_file [compression]

    name          name of the output TileSet structure
    img_file      path of the input image file (should be 8bpp .bmp or .png)
    compression   compression type (use unpackTileSet(..) to unpack)
                    -1 = AUTO (use best compression scheme)
                    0 = NONE (no compression)
                    1 = APLIB (aplib library)
                    2 = LZKN (Konami LZW compression, disable for legal reason)
                    3 = RLE (4bits RLE compression)
                    4 = RLE MAP (tilemap adapted RLE)


MAP
---
NOT YET SUPPORTED !
Take an map file as input and transform it in SGDK Map structure.
Map is used to define background plan tilemap data.

Syntax:
MAP name map_file width height [compression]

    name          name of the output Map structure
    map_file      path of the input map file (not yet defined, mappy ?)
    width         width of the map in tile
    heigth        heigth of the map in tile
    compression   compression type (use unpackMap(..) to unpack)
                    -1 = AUTO (use best compression scheme)
                    0 = NONE (no compression)
                    1 = APLIB (aplib library)
                    2 = LZKN (Konami LZW compression, disable for legal reason)
                    3 = RLE (4bits RLE compression)
                    4 = RLE MAP (tilemap adapted RLE)


IMAGE
-----
Take an image as input and transform it in SGDK Image structure.
Image is used to directly draw image in background plan, it internally contains a Palette, TileSet and Map structure.

Syntax:
IMAGE name img_file [compression]

    name          name of the output Image structure
    img_file      path of the input image file (should be 8bpp .bmp or .png)
    compression   compression type (use unpackImage(..) to unpack)
                    -1 = AUTO (use best compression scheme)
                    0 = NONE (no compression)
                    1 = APLIB (aplib library)
                    2 = LZKN (Konami LZW compression, disable for legal reason)
                    3 = RLE (4bits RLE compression)
                    4 = RLE MAP (tilemap adapted RLE)


SPRITE
------
Take an image as input and transform it in SGDK SpriteDefinition structure.
SpriteDefinition is used to draw, animate and manage sprites, it internally contains severals TileSet, Palette and Animation structures.

Syntax:
SPRITE name img_file width heigth [compression [time [collision]]]

    name          name of the output SpriteDefinition structure
    img_file      path of the input image file (should be 8bpp .bmp or .png)
    width         width of a single sprite frame in tile (should be <= 20)
    heigth        heigth of a single sprite frame in tile (should be <= 20)
    compression   compression type (use unpackSprite(..) to unpack)
                   -1 = AUTO (use best compression scheme)
                    0 = NONE (no compression)
                    1 = APLIB (aplib library)
                    2 = LZKN (Konami LZW compression, disable for legal reason)
                    3 = RLE (4bits RLE compression)
                    4 = RLE MAP (tilemap adapted RLE)
    time          display frame time in 1/60 of second (time between each animation frame)
    collision     collision type: CIRCLE, BOX or NONE (BOX by default)

Some informations about how SpriteDefinition is generated from the input image:
- input image dimension is aligned on tile (multiple of 8).
- input image is a grid where each cell represents a single sprite frame and where a row define a complete sprite animation.
- cell size (frame size) = width * height (in tile)
- a frame can be composed of several internal VDP sprites (max = 20) if width or height are > 4.
- rescomp detect flipped frame to avoid redundant sprite tiles.
- rescomp detect empty frame at end of animation row to not store empty frame data.
- rescomp detect frame copy inside an animation to generate the according animation sequence.
- collision bounds are calculated by using 75% of the original sprite frame.
- In future rescomp could detect empty tiles in a frame to optimize the internal VDP sprite usage (and also improve the collision box).
That may be a nice future addition :)


XGM
---
Take a .vgm or .xgm music file as input and transform it in binary format usable with the SGDK SND_startPlay_XGM(..) methods.
The XGM driver supports music play along 4 PCM channels mixing (100% running on Z80 cpu).

Syntax:
XGM name file

    name        XGM music variable name
    file        path of the .vgm or .xgm music file to convert to binary data array


TFM
---
Take a .tfd or .tfc music file as input and transform it in binary format usable with the SGDK SND_startPlay_TFM(..) method.

Syntax:
TFM name file z80driver

    name        TFM music variable name
    file        path of the .tfd or .tfc music file to convert to binary data array
    z80driver   when set to 1 the music is aligned in memory so you can use the Z80 driver to play it (but it consumes more ROM).


VGM
---
Take a .vgm music file as input and transform it in binary format usable with the SGDK SND_startPlay_VGM(..) method.

Syntax:
VGM name file

    name        VGM music variable name
    file        path of the .vgm music file to convert to binary data array


WAV
---
Take a .wav sound file as input and transform it to in binary format usable with one of the SGDK PCM driver.

Syntax:
WAV name file [driver [outrate]]

    name        variable name
    file        path of the .wav file (will be automatically converted to 8 bits signed PCM at needed rate)
    driver      specify the Z80 driver to use:
                0 (default) = Z80_DRIVER_PCM
                  Single channel 8 bits signed sample driver.
                  It can play a sample (8 bit signed) from 8 Khz up to 32 Khz rate.
                  Method to use: SND_startPlay_PCM(..)
                1 = Z80_DRIVER_2ADPCM
                  2 channels 4 bits ADPCM sample driver.
                  It can mix up to 2 ADCPM samples at a fixed 22050 Hz rate.
                  Method to use: SND_startPlay_2ADPCM(..)
                2 = Z80_DRIVER_4PCM
                  4 channels 8 bits signed sample driver.
                  It can mix up to 4 samples (8 bit signed) at a fixed 16 Khz rate.
                  Method to use: SND_startPlay_4PCM(..)
                3 = Z80_DRIVER_4PCM_ENV
                  4 channels 8 bits signed sample driver with volume support.
                  It can mix up to 4 samples (8 bit signed) at a fixed 16 Khz rate.
                  with volume support (16 levels du to memory limitation).
                  Method to use: SND_startPlay_4PCM_ENV(..)
                4 = Z80_DRIVER_VGM
                  VGM music driver with 8 bits PCM SFX support.
                  It supports single PCM SFX at a fixed ~9 Khz rate while playing VGM music.
                  Method to use: SND_playSfx_VGM(..)
                5 = Z80_DRIVER_XGM
                  XGM music with 4 channels 8 bits samples driver.
                  It supports 4 PCM SFX at a fixed 14 Khz rate while playing XGM music.
                  Methods to use: SND_setPCM_XGM(..) and SND_startPlayPCM_XGM(..)
    outrate     output PCM rate (only used for Z80_DRIVER_PCM driver)
                  By default the default WAV output rate is used.


PCM
---
Take a .pcm sound file as input and transform it in binary format usable with one of the SGDK PCM driver.

Syntax:
PCM name file [driver]

    name        variable name
    file        path of the PCM data file
                Should be 8 bits PCM signed data and size need to be aligned to 256 for correct loop operation
    driver      specify the Z80 driver to use:
                0 (default) = Z80_DRIVER_PCM
                  Single channel 8 bits signed sample driver.
                  It can play a sample (8 bit signed) from 8 Khz up to 32 Khz rate.
                  <b>Input:</b> 8 bits signed PCM at 8000 / 11025 / 13400 / 16000 / 22050 / 32000 Hz
                  Method to use: SND_startPlay_PCM(..)
                1 = Z80_DRIVER_2ADPCM
                  2 channels 4 bits ADPCM sample driver.
                  It can mix up to 2 ADCPM samples at a fixed 22050 Hz rate.
                  <b>Input:</b> 8 bits signed PCM at 22050 Hz
                  Method to use: SND_startPlay_2ADPCM(..)
                2 = Z80_DRIVER_4PCM
                  4 channels 8 bits signed sample driver.
                  It can mix up to 4 samples (8 bit signed) at a fixed 16 Khz rate.
                  <b>Input:</b> 8 bits signed PCM at 16000 Hz
                  Method to use: SND_startPlay_4PCM(..)
                3 = Z80_DRIVER_4PCM_ENV
                  4 channels 8 bits signed sample driver with volume support.
                  It can mix up to 4 samples (8 bit signed) at a fixed 16 Khz rate.
                  with volume support (16 levels du to memory limitation).
                  <b>Input:</b> 8 bits signed PCM at 16000 Hz
                  Method to use: SND_startPlay_4PCM_ENV(..)
                4 = Z80_DRIVER_VGM
                  VGM music driver with 8 bits PCM SFX support.
                  It supports single PCM SFX at a fixed ~9 Khz rate while playing VGM music.
                  <b>Input:</b> 8 bits signed PCM at 8000 Hz
                  Method to use: SND_playSfx_VGM(..)
                5 = Z80_DRIVER_XGM
                  XGM music with 4 channels 8 bits samples driver.
                  It supports 4 PCM SFX at a fixed 14 Khz rate while playing XGM music.
                  Methods to use: SND_setPCM_XGM(..) and SND_startPlayPCM_XGM(..)


BIN
---
Take any data file as input and transform it in binary data array accessible through SGDK.

Syntax:
BIN name file align salign fill

    name        BIN data variable name
    file        path of the data file to convert to binary data array
    align       memory address alignment for generated data array (default is 2)
    salign      size alignment for the generated data array (default is 2)
    fill        fill value for the size alignment (default is 0)
